<%@ page language="java" import="java.util.*"
	contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ page import="com.model.Building"%>
<%@ page import="com.model.Student"%>
<%@ page import="com.control.BuildingControl"%>
<%@ page import="com.control.StudentControl"%>
<%@ page import="com.util.PageResultSet"%>

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
	<head>
		<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
		<title>查询学生信息</title>
	</head>
	<body>
		<%
	    request.setCharacterEncoding("UTF-8");
	    int curPage = 1;
	    String ToolBar = "";
	    int building_id = 0;
	    String stu_name = "";
	    String stu_dorm_name = "";
	    if(request.getParameter("building") != null) {
	    	building_id = Integer.parseInt(request.getParameter("building"));
	    	session.setAttribute("building_id",building_id);	
	    	stu_name = request.getParameter("name");
	    	session.setAttribute("stu_name",stu_name);
	    	stu_dorm_name = request.getParameter("dorm");
	    	session.setAttribute("stu_dorm_name",stu_dorm_name);
	    }
		%>
		<table width="98%" border="0" align="center">
			<tr>
				<td></td>
			</tr>
			<tr>
				<td></td>
			</tr>
			<tr>
				<td>
					<fieldset>
						<legend>
							学生信息列表
						</legend>
						<form action="studentInfo_show.jsp" name="form1" method="post">
							<table width="100%" border="0" cellspacing="0" cellpadding="0">
								<tr height="10">
									<td></td>
								</tr>
								<tr align="center">
									<td align="center">
								                    
								        <%
								        	if(session.getAttribute("stu_name") != null) {
	    										stu_name = (String)session.getAttribute("stu_name");
	    									}
								         %>
								                    姓名：
								        <input name="name" type="text" id="name" size="5" <%if(!stu_name.equals(""))%> value="<%=stu_name %>"/>
										&nbsp;寝室楼:
										<select name="building" size="1">
										<%
										if(session.getAttribute("building_id") != null) {
	    										building_id = (Integer)session.getAttribute("building_id");
	    									}
										 %>
											<option value="0" <%if(building_id == 0) {%>selected="selected"<%}%>>全部</option>
											<%
											BuildingControl control = new BuildingControl();
											ArrayList<Building> blist = new ArrayList<Building>();
											blist = control.getBuildingList(); 
											for(int i=0; i<blist.size(); i++) {
												Building building = blist.get(i);
										%>
											<option value="<%= building.getBuilding_id()%>" <%if(building_id == building.getBuilding_id()%><%){%>selected="selected"<%}%>><%=building.getBuilding_name() %></option>
											<%}%>
										</select>
										  <%
								        	if(session.getAttribute("stu_dorm_name") != null) {
	    										stu_dorm_name = (String)session.getAttribute("stu_dorm_name");
	    									}
								          %>
								          &nbsp;寝室：
								        <input name="dorm" type="text" id="dorm" size="5" <%if(!stu_dorm_name.equals(""))%> value="<%=stu_dorm_name %>"/>
										<input type="submit" value="查询" />
										<input name="insert" type="button" value="添加学生"
											onclick="window.location.href='student_insert.jsp'" />
									</td>
								</tr>
							</table>
							<table width="90%" border="0" align="center" cellspacing="0"
								cellpadding="0">
								<tr>
									<td height="20"></td>
								</tr>
								<tr>
									<td>
										<table border="1" width="99%" align="center" cellpadding="0"
											cellspacing="1" class="resultTable">
											<tr>
												<td width="4%" height="25" align="center" bgcolor="#D9F0FF">
													学号
												</td>
												<td width="4%" height="25" align="center" bgcolor="#D9F0FF">
													姓名
												</td>
												<td width="2%" height="25" align="center" bgcolor="#D9F0FF">
													性别
												</td>
												<td width="4%" height="25" align="center" bgcolor="#D9F0FF">
													生日
												</td>
												<td width="4%" height="25" align="center" bgcolor="#D9F0FF">
													电话号码
												</td>
												<td width="4%" height="25" align="center" bgcolor="#D9F0FF">
													学院
												</td>
												<td width="4%" height="25" align="center" bgcolor="#D9F0FF">
													专业
												</td>
												<td width="3%" height="25" align="center" bgcolor="#D9F0FF">
													寝室楼
												</td>
												<td width="3%" height="25" align="center" bgcolor="#D9F0FF">
													寝室
												</td>
												<td width="5%" height="25" align="center" bgcolor="#D9F0FF">
													操作
												</td>
								</tr>
								<%
									StudentControl scontrol = new StudentControl();
									ArrayList<Student> list = new ArrayList<Student>();
									list = scontrol.getStuInformation(stu_name, building_id, stu_dorm_name);
									if(request.getParameter("cur_page")!= null) {
										curPage = Integer.parseInt(request.getParameter("cur_page")); 
									}
									PageResultSet p = new PageResultSet(list,curPage);
									ArrayList<Student> nowlist = new ArrayList<Student>();
									nowlist = (ArrayList<Student>)p.getData();
										
									for(int i=0; i<nowlist.size(); i++) {
										Student student = nowlist.get(i);
							 	%>
								 	<tr>
        								<td height="25" align="center"><%=student.getStu_num()%></td>
 										<td height="25" align="center"><%=student.getStu_name()%></td>
 										<td height="25" align="center"><%=student.getStu_sex()%></td>
 										<td height="25" align="center"><%=student.getStu_birth()%></td>
 										<td height="25" align="center"><%=student.getStu_tel()%></td>
 										<td height="25" align="center"><%=student.getStu_college()%></td>
 										<td height="25" align="center"><%=student.getStu_major()%></td>
 										<td height="25" align="center"><%=student.getStu_building_name()%></td>	
 										<td height="25" align="center"><%=student.getStu_dorm_name()%></td>
 		 								<td height="25" align="center"><a href="studentInfo_change.jsp?id=<%=student.getStu_id()%>">修改</a> | <a href="javascript:if(confirm('确认删除吗?'))window.location='student_delete.jsp?id=<%=student.getStu_id()%>'">删除</a></td>
   									</tr>
   									<%}
   										
										String fileName = "studentInfo_show.jsp";
										ToolBar = p.getToolBar(fileName);
									%>
							</table>
							<%=ToolBar %>
							</td>
							</tr>
							</table>
						</form>
					</fieldset>
				</td>
			</tr>
		</table>
	</body>
</html>
